
package bsc.war.ajax;

import bsc.ejb.entity.Dimension;
import bsc.ejb.entity.DimensionMember;
import bsc.war.delegate.DelegateBSC;
import bsc.war.factory.Factory;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.math.NumberUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 *
 * @author castrosalazr
 */
public class DesignerAddDimension extends AbstractController  {

     @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request,
         HttpServletResponse response) throws Exception {

        try {
            DelegateBSC delegate = (DelegateBSC) Factory.getBean("DelegateBSC");
            String type = request.getParameter("type");
            Dimension dimension = "edit".equals(type) && NumberUtils.isDigits(request.getParameter("id")) ? delegate.findDimension(Long.valueOf(request.getParameter("id"))) : null;
            DimensionMember totalMember = dimension != null ? delegate.findDimensionMember(dimension).get(0) : null;
            request.setAttribute("dimension", dimension);
            request.setAttribute("totalMember", totalMember);
            request.setAttribute("edit","edit".equals(type));
        } catch (Exception e) {
        }

         return new ModelAndView("designerAddDimension");
    }
}
